package com.cdtye.itps.cms.service.warn;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdtye.common.mybatiscore.base.BaseService;
import com.cdtye.common.webcore.constants.WebConstants;
import com.cdtye.itps.cms.dao.enums.DelFlagEnum;
import com.cdtye.itps.cms.dao.warn.entity.JcjcWarnFiles;
import com.cdtye.itps.cms.dao.warn.vo.JcjcWarnFilesVo;
import com.cdtye.itps.cms.mapper.warn.JcjcWanFilesMapper;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class JcjcWarnFilesService extends BaseService<JcjcWanFilesMapper, JcjcWarnFiles> {

    /**
     * 新增文件
     */
    public void insertJcjcWarnFiles(List<JcjcWarnFiles> list,String bizId,String name)
    {
        this.deleteByBizId(bizId);
        list.forEach(jcjcWarnFiles -> {
            jcjcWarnFiles.setBizId(bizId);
            jcjcWarnFiles.setDelFlag(DelFlagEnum.NO.value);
            Date dNow = new Date( );
            jcjcWarnFiles.setCreateBy(name);
            jcjcWarnFiles.setUpdateBy(name);
            jcjcWarnFiles.setCreateDatetime(dNow);
            jcjcWarnFiles.setUpdateDatetime(dNow);
            jcjcWarnFiles.setStatus("NORMAL");
        });
        this.saveBatch(list);
    }



    /**
     * 根据BizId进行逻辑删除
     */
    public void deleteByBizId(String bizId)
    {
        UpdateWrapper<JcjcWarnFiles> updateWrapper_files = new UpdateWrapper<>();
        updateWrapper_files.eq("BIZ_ID", bizId);
        updateWrapper_files.set("DEL_FLAG","Y");
        update(updateWrapper_files);
    }

    /**
     * 列表查询
     */
    public List<JcjcWarnFiles> list(JcjcWarnFilesVo vo){
        LambdaQueryWrapper<JcjcWarnFiles> wrapper = new LambdaQueryWrapper<>();
        //物理删除表,查询非删除状态包括null
        wrapper.and(i->i.eq(JcjcWarnFiles::getDelFlag, WebConstants.NO).or().isNull(JcjcWarnFiles::getDelFlag));
        return list(wrapper);
    }

    /**
     * 分页查询，自定义sql语句
     */
    public IPage<Map<String,Object>> listPage(JcjcWarnFilesVo vo){
        return baseMapper.pageList(vo.page(), vo);
    }

}
